<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
</body>
<script>
// 创建对象池工厂
class ObjectPoolFactory {
  constructor(createObjFn) {
    this.objectPool = []
    this.createObjFn = createObjFn
  }
  create() {
    let obj = this.objectPool.length 
      ? this.objectPool.shift()
      : this.createObjFn.apply(this, arguments)
      return obj
  }
  recover(obj) {
    this.objectPool.push(obj)
  }
}
// 创建装载一些iframe的对象池
function createIframe() {
  return () => {
    let iframe = document.createElement('iframe')
    document.body.appendChild(iframe)
    iframe.onload = () => {
      iframe.onload = null // 防止重复加载
      iframeFactory.recover(iframe) // 加载完回收节点
    }
    return iframe
  }
}
let iframeFactory = new ObjectPoolFactory(createIframe())
var iframe1 = iframeFactory.create()
iframe1.src = 'http://baidu.com'
var iframe2 = iframeFactory.create()
iframe2.src = 'http://QQ.com'
setTimeout(() => {
  let iframe3 = iframeFactory.create()
  iframe3.src = 'http://163.com'
}, 3000)
</script>
</html>